// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <MovieSequenceCompositeTransition.h>

#include <WidgetDataNode.h>
#include <QvisCompositeTransition.h>
#include <DebugStream.h>

// Icons
#include <icons/ms_comp_fadein.xpm>
#include <icons/ms_comp_fadeout.xpm>
#include <icons/ms_comp_lr_slide.xpm>
#include <icons/ms_comp_rl_slide.xpm>
#include <icons/ms_comp_tb_slide.xpm>
#include <icons/ms_comp_bt_slide.xpm>

// ****************************************************************************
// Method: MovieSequenceCompositeTransition::MovieSequenceCompositeTransition
//
// Purpose: 
//   Base class constructor for composite transition sequences.
//
// Programmer: Brad Whitlock
// Creation:   Tue Nov 14 10:44:20 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

MovieSequenceCompositeTransition::MovieSequenceCompositeTransition() :
    MovieSequence()
{
}

// ****************************************************************************
// Method: MovieSequenceCompositeTransition::~MovieSequenceCompositeTransition
//
// Purpose: 
//   Destructor.
//
// Programmer: Brad Whitlock
// Creation:   Tue Nov 14 10:44:50 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

MovieSequenceCompositeTransition::~MovieSequenceCompositeTransition()
{
}

// ****************************************************************************
// Method: MovieSequenceCompositeTransition::CreateUI
//
// Purpose: 
//   Create the user interface for the sequence.
//
// Returns:    A pointer to the new user interface object.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Tue Nov 14 10:45:01 PDT 2006
//
// Modifications:
//   Brad Whitlock, Tue Apr  8 10:33:54 PDT 2008
//   SequenceMenuName now returns QString.
//
//   Brad Whitlock, Tue Oct  7 11:21:26 PDT 2008
//   Qt 4.
//
// ****************************************************************************

QWidget *
MovieSequenceCompositeTransition::CreateUI()
{
    QvisCompositeTransition *ui = new QvisCompositeTransition(Pixmap(), 0);
    ui->setObjectName(GetName().c_str());
    ui->setTitle(SequenceMenuName());

    return ui;
}

// ****************************************************************************
// Method: MovieSequenceCompositeTransition::ReadUIValues
//
// Purpose: 
//   Gets the values from the data node and updates the user interface.
//
// Arguments:
//   ui   : The user interface.
//   node : The node in which to insert the sequence's data values.
//
// Programmer: Brad Whitlock
// Creation:   Tue Nov 14 10:40:58 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

void
MovieSequenceCompositeTransition::ReadUIValues(QWidget *ui, DataNode *node)
{
    const char *mName = "MovieSequenceCompositeTransition::ReadUIValues: ";

    if(node != 0)
    {
        QvisCompositeTransition *UI = (QvisCompositeTransition *)ui;

        // Read the number of frames.
        DataNode *nFramesNode = node->GetNode("nFrames");
        if(nFramesNode !=0 && nFramesNode->GetNodeType() == INT_NODE)
        {
            UI->setNFrames(nFramesNode->AsInt());
        }
        else
        {
            debug4 << mName << "nFrames not found in node." << endl;
        }

        // Read the reverse flag.
        DataNode *reverseNode = node->GetNode("reverse");
        if(reverseNode !=0 && reverseNode->GetNodeType() == BOOL_NODE)
        {
            UI->setReverse(reverseNode->AsBool());
        }
        else
        {
            debug4 << mName << "reverse not found in node." << endl;
        }
    }
}

// ****************************************************************************
// Method: MovieSequenceCompositeTransition::WriteUIValues
//
// Purpose: 
//   Gets data values from the user interface and inserts them into the
//   data node representation where they can be written to the template
//   specification file.
//
// Arguments:
//   ui   : The user interface.
//   node : The node in which to insert the sequence's data values.
//
// Programmer: Brad Whitlock
// Creation:   Tue Nov 14 10:40:58 PDT 2006
//
// Modifications:
//   
// ****************************************************************************

void
MovieSequenceCompositeTransition::WriteUIValues(QWidget *ui, DataNode *node)
{
    if(node != 0)
    {
        QvisCompositeTransition *UI = (QvisCompositeTransition *)ui;
        node->RemoveNode("nFrames");
        node->AddNode(new DataNode("nFrames", UI->getNFrames()));

        node->RemoveNode("reverse");
        node->AddNode(new DataNode("reverse", UI->getReverse()));
    }
}

//
// Pixmap and menu name methods for the derived classes.
//

QPixmap
MovieSequenceCompositeFadeIn::Pixmap()
{
    return QPixmap(ms_comp_fadein_xpm);
}

QString
MovieSequenceCompositeFadeIn::SequenceMenuName() const
{
    return tr("Fade in viewport");
}

////////////////////////////////////////////////////////////////////////////////

QPixmap
MovieSequenceCompositeFadeOut::Pixmap()
{
    return QPixmap(ms_comp_fadeout_xpm);
}

QString
MovieSequenceCompositeFadeOut::SequenceMenuName() const
{
    return tr("Fade out viewport");
}

////////////////////////////////////////////////////////////////////////////////

QPixmap
MovieSequenceCompositeLRSlide::Pixmap()
{
    return QPixmap(ms_comp_lr_slide_xpm);
}

QString
MovieSequenceCompositeLRSlide::SequenceMenuName() const
{
    return tr("Slide in viewport left to right");
}

////////////////////////////////////////////////////////////////////////////////

QPixmap
MovieSequenceCompositeRLSlide::Pixmap()
{
    return QPixmap(ms_comp_rl_slide_xpm);
}

QString
MovieSequenceCompositeRLSlide::SequenceMenuName() const
{
    return tr("Slide in viewport right to left");
}

////////////////////////////////////////////////////////////////////////////////

QPixmap
MovieSequenceCompositeTBSlide::Pixmap()
{
    return QPixmap(ms_comp_tb_slide_xpm);
}

QString
MovieSequenceCompositeTBSlide::SequenceMenuName() const
{
    return tr("Slide in viewport top to bottom");
}

////////////////////////////////////////////////////////////////////////////////

QPixmap
MovieSequenceCompositeBTSlide::Pixmap()
{
    return QPixmap(ms_comp_bt_slide_xpm);
}

QString
MovieSequenceCompositeBTSlide::SequenceMenuName() const
{
    return tr("Slide in viewport bottom to top");
}

